import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  server: {
    proxy: {
      '/api/twqh': {
        target: 'https://api.zxki.cn',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api\/twqh/, '/api/twqh')
      },
      '/api/yiju': {
        target: 'https://api.t1qq.com',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api\/yiju/, '/api/tool/yiyan?key=pBwphVkuhG0hBF57EQwqahRUxR')
      },
      '/api/xhy': {
        target: 'https://www.mxnzp.com',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api\/xhy/, '/api/xiehouyu/random?app_id=mrfjmtn2heawpjif&app_secret=wctcTdWBenOALNujImfp9F1rZZkTPOXF')
      },
      '/api/yigu': {
        target: 'https://www.mxnzp.com',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api\/yigu/, '/api/story/details')
      }
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
})
